﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using HotSpot.Silverlight.Web.DomainServices;
using HotSpot.Silverlight.Web.DAL;

namespace HotSpot.Silverlight
{
    public partial class HSAccommodation : Page
    {
        public HSAccommodation()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(HSAccommodation_Loaded);
        }
                
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

        void HSAccommodation_Loaded(object sender, RoutedEventArgs e)
        {
            HotSpotDomainContext hsContext = new HotSpotDomainContext();

            if (!this.NavigationContext.QueryString.ContainsKey("searchText"))
            {
                hsContext.Load(hsContext.GetAccommodationSearchQuery(
                "",
                0,
                0,
                0,
                false,
                false,
                false,
                false,
                false,
                false,
                false
                ));
                HotelList.ItemsSource = hsContext.Accommodations;
                
                return;
            }

            #region Get the query strings
            string searchText = this.NavigationContext.QueryString["searchText"];
            int idCountry = int.Parse(this.NavigationContext.QueryString["idCountry"]);
            int idTown = int.Parse(this.NavigationContext.QueryString["idTown"]);
            int stars = int.Parse(this.NavigationContext.QueryString["stars"]);
            bool detaliedSearchTags = bool.Parse(this.NavigationContext.QueryString["detaliedSearchTags"]);
            bool allowPets = bool.Parse(this.NavigationContext.QueryString["allowPets"]);
            bool restaurant = bool.Parse(this.NavigationContext.QueryString["restaurant"]);
            bool spa = bool.Parse(this.NavigationContext.QueryString["spa"]);
            bool pool = bool.Parse(this.NavigationContext.QueryString["pool"]);
            bool parking = bool.Parse(this.NavigationContext.QueryString["parking"]);
            bool conferenceRoom = bool.Parse(this.NavigationContext.QueryString["conferenceRoom"]);
            #endregion
            
            hsContext.Load(hsContext.GetAccommodationSearchQuery(
                searchText,
                idCountry,
                idTown,
                stars,
                detaliedSearchTags,
                allowPets,
                restaurant,
                spa,
                pool,
                parking,
                conferenceRoom
                ));

            HotelList.ItemsSource = hsContext.Accommodations;
        }
    }
}
